package com.guoxin.part1.chapter5;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/28
 */
public class EventClient {
    public static void main(String[] args) {

        EventQueue<String> eventQueue = new EventQueue<>(0);
        new Thread(() -> {
            for (; ; ) {
                eventQueue.offer(String.valueOf(Math.random()));
            }
        }, "Producer").start();

        new Thread(() -> {
            for (; ; ) {
                try {
                    eventQueue.take();
                    TimeUnit.MILLISECONDS.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "Consumer-1").start();

        new Thread(() -> {
            for (; ; ) {
                eventQueue.take();
            }
        }, "Consumer-2").start();

        new Thread(() -> {
            for (; ; ) {
                eventQueue.take();
            }
        }, "Consumer-3").start();
    }
}
